import cv2
import numpy as np
import os
RECOGNIZER = cv2.face.LBPHFaceRecognizer_create()  # LBPH识别器
#RECOGNIZER = cv2.face.EigenFaceRecognizer_create()#特征脸识别器
# RECOGNIZER = cv2.face.FisherFaceRecognizer_create()  # LBPH识别器
PASS_CONF = 45  # 最高评分，LBPH最高建议用45，特征脸最高建议用22000
FACE_CASCADE = cv2.CascadeClassifier(os.getcwd() + "\\cascades\\haarcascade_frontalface_default.xml")  # 加载人脸识别级联分类器
def train(photos,lables):
    print(str(lables))
    RECOGNIZER.train(photos,np.array(lables))
def found_face(gary_img):
    faces= FACE_CASCADE.detectMultiScale(gary_img,1.15)
    if len(faces)==0:
        print("No faces")
    return len(faces)>0
def recognise_face(photo):
    label,confidence=RECOGNIZER.predict(photo)
    # if confidence>PASS_CONF:
    #     print("识别错误")
    #     return -1

    return label
